package peng.controller.AppResult;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
import peng.entity.AdminUser;
import peng.entity.AdminUserMenu;
import peng.service.AdminUserMenuService;
import sun.plugin2.message.Message;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;


@RestController
public class AdminUserMenuController {
    @Resource
    private AdminUserMenuService adminUserMenuService;

    /**
     *根据id删除
     * @return
     */
    @RequestMapping("/deleteMen")
    public  ResultMessage deleteByPrimaryKey(Integer id) {
        int count = adminUserMenuService.deleteByPrimaryKey(id);
        if (count > 0) {
            return new ResultMessage(ResultMessage.code_OK_1, "成功");
        }
        return new ResultMessage(ResultMessage.code_FAIL_0, "失败");
    }

    /**
     * 动态添加
     * @return
     */
    @RequestMapping("/addMen")
    public ResultMessage insertSelective(AdminUserMenu record){
        int count=adminUserMenuService.insertSelective(record);
        if (count > 0) {
            return new ResultMessage(ResultMessage.code_OK_1, "成功");
        }
        return new ResultMessage(ResultMessage.code_FAIL_0, "失败");
    }

    /**
     * 权限列表
     * @param model
     * @return
     */
    @RequestMapping("showmens")
    public String showmens(Model model){
    List<AdminUserMenu> list=adminUserMenuService.listmens();
    if (list!=null){
       model.addAttribute("list",list);
    }else {
        model.addAttribute("error","没有相关数据，请重试！");
    }
    return "add";
    }
    /**
     * 查詢一条数据
     * @param id
     * @return
     */
    @RequestMapping("/selectMenKey")
    public ResultMessage selectByPrimaryKey(Integer id){
        AdminUserMenu record=adminUserMenuService.selectByPrimaryKey(id);
        if (record!=null){
            return new ResultMessage(ResultMessage.code_OK_1, "成功");
        }
        return new ResultMessage(ResultMessage.code_FAIL_0, "失败");
    }

    /**
     * 修改信息
     * @param record
     * @return
     */
    @RequestMapping("/updateMen")
    public  ResultMessage updateByPrimaryKeySelective(AdminUserMenu record){
        if (adminUserMenuService.updateByPrimaryKeySelective(record)>0){
            return new ResultMessage(ResultMessage.code_OK_1, "成功");
        }
        return new ResultMessage(ResultMessage.code_FAIL_0, "失败");
        }


}
